Beating LoLdle Using Information Theory
⚠️ Optimal inital guesses for LoLdle are available at the bottom of this article, if you don’t wish to have the game sort of spoiled.
Wordle is a game about guessing a certain 5-letter word within 5 guesses, each attempt revealing more and more about which letters appear and where. Countless clones have been spawned which twists the premise, including LoLdle. In LoLdle you guess one of the (currently) 162 champions of the game League of Legends by guessing one champion at a time. Once you have guessed a champion, the game tells you what that champion has (or doesn’t have) in common with the target champion based on the categories:
- Gender: The gender of the champion
- Position(s): Where on the map the champion is usually played
- Species: The species of the champion
- Resource: What resource the champion uses to cast spells
- Range type: Whether the champion can attack from afar or must be close
- Region(s): The region of the in-game universe where the champion originates from
An attempt at a LoLdle guess could look like this:
This attempt tells me that the target champion is not female is played in either middle or jungle, is either human or magicborn, does use mana as a resource, is ranged, belongs to Shurima (and somewhere else) and was released earlier than 2016. This reduces the possible champions a lot (foreshadowing) and a good mnemonist would easily be able to deduce available options. Still, in order to find the best guess we need good memory and math. The best guess in this sense is the guess which reduces the available guesses the most.
You have 10 champions to choose from and you must decide between guess A and B. If incorrect, guess A reduces the available pool of champions to 5. If incorrect, guess B reduces the available champion pool of champions to 2. Which guess is best?
Obviously, the better guess is the one which is correct, but if we knew that we would just guess it immediately! Therefore, the best guess is the one which reduces the available guess thereafter if the guess is incorrect. In the above example, we would rather guess B as it reduces the available champions by a factor 5 which is better than reducing by a factor 2 by the guess of A.
Information Theory
This metric of reducing the information space is a vital part of Information Theory, a branch of mathematics used heavily in data compression and various other branches of science. In short, how much information you acquire from a guess is dependent on the probability of getting that guess. In particular, information theory defines the Shannon entropy $H$ as: $$ H = -\sum_i p_i \log_2 (p_i) $$ Say you guess champ that divides the full champion pool of 162 into two pools. A pool of 54 where the properties match and a pool of 108 where they don’t. The probability of the target champion belonging to the first pool is $p_1 = 54/162=1/3$. The probability of the target champion belonging to the second is $p_2 = 108/64=2/3$. The Shannon entropy for this guess therefore becomes $$ H = - 1/3 \log_2(1/3) - 2/3 \log_2(2/3) = 0.92 $$ A second guess which divides the champion pool into 90 and 81 with some overlap has the following entropy: $$ H = - 90/162 \log_2(90/162) - 81/162 \log_2(81/162) = 0.97 $$ This is slightly better, as greater entropy means a larger reduction. This is because the reduction in information space for the i’th occurence is exactly $1/p_i$. This is compounded by the unit of Shannon entropy, the information bit, which represents the reduction as the amount of times the information space is halved. In the above example, the guess halves the information space $2^{0.97} = 1.96$ times!
The algorithm
You can probably already guess how I can implement this to find the best LoLdle guess for any state of the game, but let me lay it out:
- Construct the list of every possible correct champion (every champion if initial guess)
- For every correct champion calculate the different outcome pools and how many champions reside in them
- Use these pools to calculate the probability of each outcome and calculate the Shannon entropy
- List the guesses with the largest entropy
To construct the list of champions and generate the guesses, I need the data used by LoLdle. The data is acquired by scraping www.loldle.net for the bundled minified javascript before using the following regular expression to extract the variable which holds all the champion information:
=(\[\{_id:"[^{}]+championId:".+?\}\])
It is then fed through a Javascript Object to JSON Converter such that I can put it into Python for treatment. The code generates possible answers iteratively by generating a list of matching candidates, not-matching candidates and partially matching candidates for each property based on the candidates (matching, not-matching and partial) from the previous property. This means that the code is quite fast and calculating every outcome for every champion takes less than 1 second on my computer. While there are technically $7^3=343$ options, most champions have around 70 outcomes. Just a quick note: For ease of programming, an earlier year than guessed is marked as partially correct rather than incorrect to discern between them. The code can be found on GitHub.
Results
ℹ️ Fixed an error in Shannon entropy calculation where I calculated the probability of outcome as possible champions divided by the amount of outcomes rather than the amount of champions.
The entropies of each initial guess are plotted in a boxplot below. As is seen, the median is a about 5.5 but some guesses are far better. Most guesses has an entropy between 4 and 6, and as such reduce the champion pool by 16 to 64 times.
The plat seen further down shows each of the 10 best performing initial guesses and the 10 worst. Surprisingly, Talon is apparently the best guess. This is likely due to him being dual position (mid and jungle), humanoid, uses mana and was released relatively early. Guessing Talon is sort of like doing a fifty-fifty coinflip on each property, and it is therefore natural that he is the best guess. In fact, on average, guessing Talon provides, on average, $6.17$ bits of information while the entire champion pool has $\log_2(162) = 7.34$ bits of uncertainty, leaving $1.17$ bits of uncertainty. This means that guessing Talon, on average, leaves you with only $2^{1.17} \approx 2$ champions to choose from.
On the flip side, Bel’Veth, one of the newer champions, is the worst guess. This is likely due to the niche properties she has: She is a void-being (9 champions, 3 of them partial), is manaless (7 champions) and is from the Void (9 champions, 4 of them partial). Since no champion has been released yet, Bel’Veth’s release year of 2022 is a really bad property as it provides limited information when it inevitably turns incorrect ($157/162$ chance).
If you want to check how good your favorite champion fairs against the others, check out the results table.
ℹ️ The champion data for LoLdle changes quite often, so results may vary slightly from when you’re reading this.
Going further than initial guesses
The algorithm described earlier guessing the same champion every time. Firstly, it guesses Talon as he has the largest average entropy and then, based on the outcome selects the next highest entropy champion. This deterministic behaviour is pushed to the limit as I decided to simulate every outcome of the game using this algorithm. I simply simulate a game with every champion as the target unknown champion and the let the algorithm do its thing. As I haven’t optimized anything the code runs quite slowly and calculates every single game in about 30 seconds. Below is a distribution of the amount of guesses needed for every game
As you can see, the algorithm may complete any game in 4 guesses or less, and completes the majority of them within 2 or 3. In fact, only 3 champions are not guessed in 2 or 3 tries, those being Talon (since he is the initial guess every time), Zyra and Volibear. For the latter two, the guessing sequence is as follows:
Zyra: Talon > Nami > Lulu > Zyra
Volibear: Talon > Nocturne > Maokai > Volibear
You can find the sequence of guesses the algorithm makes in the table on GitHub. We can also use this information in reverse; since we always start with Talon, we can simply list every single outcome of colors and list every champion which fit the outcome. This makes the game drastically easier, as most outcomes have around 1-3 possible champions with the largest still only having 18. I won’t do that though - if you want to cheat you’re going to have to program it yourself :)
In conclusion, using information theory it is possible to very easily outperform pretty much any human player. Using information theory we have shown the best initial guess to be Talon and also calculated all subsequent guesses for every target champion. It is no surprise that information theory is a good tool for optimising games such as this - it has been used on a lot of Wordle-type games. In fact, I got my inspiration for this by watching the 3blue1brown video on the matter. This video explains the principle much better and is really interesting, so check it out.
Published 19. March 2023
Last modified 22. March 2023